#!/bin/sh -e
# Copyright (c) 2016 The crouton Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file is sourced from main.sh to update distro-specific defaults.
# It must set at least ARCH and MIRROR if not already specified.

if [ -z "$ARCH" ]; then
    ARCH="`uname -m`"
fi

case "$ARCH" in
x86 | i?86) ARCH="i386";;
x86_64 | amd64) ARCH="amd64";;
arm64 | aarch64) ARCH="arm64";;
arm*) ARCH="armhf";;
*) error 2 "Invalid architecture '$ARCH'.";;
esac

# trusty is the first release with arm64
if [ "$ARCH" = "arm64" ] && release -lt trusty; then
    ARCH="armhf"
fi

if [ -z "$MIRROR" ]; then
    if [ "$ARCH" = 'amd64' -o "$ARCH" = 'i386' ]; then
        MIRROR="${CROUTON_MIRROR_ubuntu_x86:-http://archive.ubuntu.com/ubuntu/}"
    else
        MIRROR="${CROUTON_MIRROR_ubuntu_arm:-http://ports.ubuntu.com/ubuntu-ports/}"
    fi
fi

